/**
 * Classe FramePrincipal Define todos os componentes presente na interface
 * gráfica
 *
 */

/*
 * FramePrincipal.java
 *
 * Created on 13/04/2011, 15:14:48
 */
package epibot.GUI;

import epibot.BancoDeDados.ArmazenaDados.Fasta;
import epibot.BancoDeDados.Tabelas;
import epibot.Help.AboutEPIBOT;
import epibot.QualificaSites.JPanelQualificaSites;
import epibot.robot.Proxy.FrameProxy;
import epibot.testeProteinas.JPanelTesteProteinas;
import epibot.testeProteinas.JPanelBuscaRobot;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Rafael Tosta
 */
public class FramePrincipal extends javax.swing.JFrame {

    /**
     * Construtor - Cria o frame principal
     */
    public FramePrincipal() {
        this.setTitle("EPIBOT - Epitope Discovery");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/epibot/GUI/appICO.png"));
        this.setIconImage(imagemTitulo);

        initComponents();
        this.painelPrincipal.add(new JPanelInicial());
        setLocationRelativeTo(null);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        painelPrincipal = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuProxy = new javax.swing.JMenuItem();
        jMenuItemAbout = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuQualificaSites = new javax.swing.JMenuItem();
        jMenuPrediction = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jPanel2.setBackground(new java.awt.Color(153, 153, 153));

        painelPrincipal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        painelPrincipal.setLayout(new javax.swing.BoxLayout(painelPrincipal, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 975, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)
        );

        jMenuFile.setText("Main");

        jMenuProxy.setText("Proxy Server");
        jMenuProxy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuProxyActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuProxy);

        jMenuItemAbout.setText("About");
        jMenuItemAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemAboutActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemAbout);

        jMenuItem5.setText("Exit");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItem5);

        jMenuBar1.add(jMenuFile);

        jMenu3.setText("Run");

        jMenuQualificaSites.setText("Setup");
        jMenuQualificaSites.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuQualificaSitesActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuQualificaSites);

        jMenuPrediction.setText("Prediction");
        jMenuPrediction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuPredictionActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuPrediction);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Visualiza as proteinas
     *
     * @param evt
     */
    private void menuAbreArqInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuAbreArqInActionPerformed
//        this.jTextAreaAvisos.setText("");
//        this.visualizarProteinas();
    }//GEN-LAST:event_menuAbreArqInActionPerformed

    /**
     * Define o proxy do sistema
     *
     * @param evt
     */
    private void jMenuProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuProxyActionPerformed
        new FrameProxy(this).setVisible(true);
    }//GEN-LAST:event_jMenuProxyActionPerformed
    /**
     * Inicia o browser com o html do help
     *
     * @param evt
     */
private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAboutActionPerformed
    new AboutEPIBOT(this).setVisible(true);
}//GEN-LAST:event_jMenuItemAboutActionPerformed

private void jMenuQualificaSitesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuQualificaSitesActionPerformed
    atualizaFrame();
    /**
     * Neste evento será realizados 3 operações: 1 - Pedi ao usuário a lista de
     * epitopos calibradores 2 - Consultas nos sites 3 - gera as notas dos sites
     */
    this.qualificaSites();
}//GEN-LAST:event_jMenuQualificaSitesActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
    dispose();
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuPredictionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuPredictionActionPerformed
    testeDeProteinas();
}//GEN-LAST:event_jMenuPredictionActionPerformed
//    

    /**
     * metodo que realiza 3 operações: 1 - Pedi ao usuário a lista de epitopos
     * calibradores 2 - Consultas nos sites 3 - gera as notas dos sites
     */
    private void qualificaSites() {
        this.painelPrincipal.removeAll();
        this.painelPrincipal.add(new JPanelQualificaSites(this));
        this.show();
    }

    /**
     * Atualiza frame
     */
    public void atualizaFrame() {
        this.painelPrincipal.removeAll();
        this.painelPrincipal.add(new JPanelInicial());
        this.show();
    }
    
    
     public void buscaTeste(ArrayList<Fasta> fastas, ArrayList<String> motores, String tamanho, String alelo, String nomeDaCalibragem) {
        this.painelPrincipal.removeAll();
        this.painelPrincipal.add(new JPanelBuscaRobot(this, fastas, motores, tamanho, alelo, nomeDaCalibragem));
        this.show();
    }

    /**
     * Inicia o consolidador
     */
    private void testeDeProteinas() {

        boolean emptyCal = Tabelas.getTabelaNotaDoSite().isEmpty();

        //JOptionPane.showMessageDialog(this.framePrincipal, "Canceled operation!\n");
        if (!emptyCal) {//ta vazio
            JOptionPane.showMessageDialog(this, "Canceled operation!\n"
                    + "Calibrator not exist in database!\n\nPlease, calibrate the predicting sites");

            this.qualificaSites();
        } else {
            this.painelPrincipal.removeAll();
            this.painelPrincipal.add(new JPanelTesteProteinas(this));
            this.show();
        }
    }

    public JPanel getPainelPrincipal() {
        return painelPrincipal;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItemAbout;
    private javax.swing.JMenuItem jMenuPrediction;
    private javax.swing.JMenuItem jMenuProxy;
    private javax.swing.JMenuItem jMenuQualificaSites;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel painelPrincipal;
    // End of variables declaration//GEN-END:variables

    
}
